package lc.模拟;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/17
 */
public class Bank {

    long[] arr;
    public Bank(long[] balance) {
        arr = new long[balance.length + 1];
        for (int i = 0; i < balance.length; i++) {
            arr[i + 1] = balance[i];
        }

    }

    public boolean transfer(int account1, int account2, long money) {

        if (account1 < 0 || account1 > arr.length || account2 < 0 || account2 > arr.length) {
            return false;
        }

        if (arr[account1] >= money) {
            arr[account1]-= money;
            arr[account2] += money;
            return true;
        }
        return false;

    }

    public boolean deposit(int account, long money) {

        if (account < 0 || account > arr.length) {
            return false;
        }
        arr[account]+= money;
        return true;
    }

    public boolean withdraw(int account, long money) {

        if (account < 0 || account > arr.length) {
            return false;
        }
        if (arr[account] >= money) {
            arr[account] -= money;
            return true;
        }
        return false;
    }

}
